from django.db import models

from utils.BaseModel import BaseModel


# Create your models here.

class UserModel(BaseModel):
    username = models.CharField(max_length=32, verbose_name='用户名')
    password = models.CharField(max_length=32, verbose_name='密码')
    email = models.EmailField(verbose_name='邮箱', unique=True)
    phone = models.CharField(max_length=11, unique=True, verbose_name='手机号')
    headind = models.CharField(max_length=255, null=True, blank=True, verbose_name='用户头像')
    intro = models.CharField(max_length=255, verbose_name='用户简介', default="")
    score = models.IntegerField(default=100, verbose_name='用户积分')
    level = models.IntegerField(choices=((0, '普通用户'), (1, '银牌'), (2, '金牌')), default=0, verbose_name='用户等级')

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'fguser'


class CouponModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name='优惠券名称')
    price = models.IntegerField(verbose_name='优惠券金额')
    end_time = models.DateTimeField(verbose_name='优惠券结束时间')
    number = models.IntegerField(verbose_name='优惠券数量')
    condition = models.CharField(max_length=255, verbose_name='使用条件')
    desc = models.CharField(max_length=255, verbose_name='优惠券描述')

    class Meta:
        db_table = 'fgcoupon'

    def __str__(self):
        return self.name


class UserCoupon(BaseModel):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name='用户')
    coupon = models.ForeignKey(CouponModel, on_delete=models.CASCADE, verbose_name='优惠券')
    isused = models.BooleanField(default=False, verbose_name='是否使用')

    class Meta:
        db_table = 'fgusercoupon'
